package com.shuaigef.springbootinit.model.enums;

import com.shuaigef.springbootinit.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ExerciseDifficulty {

    EASY("一", 1),  // 难度一
    MEDIUM("二", 2), // 难度二
    HARD("三", 3),   // 难度三
    VERY_HARD("四", 4), // 难度四
    EXTREME("五", 5);  // 难度五

    private final String label;
    private final int level;

    public static ExerciseDifficulty getDifficultyByLabel(String label) {
        for (ExerciseDifficulty difficulty : ExerciseDifficulty.values()) {
            if (difficulty.label.equals(label)) {
                return difficulty;
            }
        }
        throw new BusinessException(400,"无效的难度标签: " + label);
    }

    public static ExerciseDifficulty getDifficultyByLevel(Integer level) {
        for (ExerciseDifficulty difficulty : ExerciseDifficulty.values()) {
            if (difficulty.level==level) {
                return difficulty;
            }
        }
        throw new BusinessException(400,"无效的难度标签: " + level);
    }
}
